﻿using System.Web;
using System.Web.UI;

namespace PAS.Helper
{
    public class SessionHelper
    {
        public static void SetSession(Page p, string key, object val)
        {
            p.Session[GetKeyHeadString() + key] = val;
        }

        public static object GetSession(Page p, string key)
        {
            string keyVal = GetKeyHeadString() + key;
            if (p.Session[keyVal] != null)
                return p.Session[keyVal];
            return null;
        }

        private static string GetKeyHeadString()
        {
            return HttpContext.Current.Request.Url.AbsolutePath.Replace("/", "_");
        }

        public static void SetSession(Control ctl, string key, object val)
        {
            string keyVal = GetKeyHeadString() + ctl.ID + key;
            HttpContext.Current.Session[keyVal] = val;
        }

        public static object GetSession(Control ctl, string key)
        {
            string keyVal = GetKeyHeadString() + ctl.ID + key;
            if (HttpContext.Current.Session[keyVal] != null)
                return HttpContext.Current.Session[keyVal];
            return null;
        }
    }
}